﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Planargraph
{
	public class NodeMap
	{
		public Node Add(Node n)
		{
			this._nodeMap[n.Coordinate] = n;
			return n;
		}

		public Node Remove(Coordinate pt)
		{
			if (!this._nodeMap.ContainsKey(pt))
			{
				return null;
			}
			Node result = this._nodeMap[pt];
			this._nodeMap.Remove(pt);
			return result;
		}

		public Node Find(Coordinate coord)
		{
			Node result;
			if (this._nodeMap.TryGetValue(coord, out result))
			{
				return result;
			}
			return null;
		}

		public IEnumerator<Node> GetEnumerator()
		{
			return this._nodeMap.Values.GetEnumerator();
		}

		public ICollection<Node> Values
		{
			get
			{
				return this._nodeMap.Values;
			}
		}

		public int Count
		{
			get
			{
				return this._nodeMap.Count;
			}
		}

		private readonly IDictionary<Coordinate, Node> _nodeMap = new SortedDictionary<Coordinate, Node>();
	}
}
